﻿// 这里放的是CPU运行各时点的回调，但基本没用上
namespace DA6502.CPU
{
    using addr = System.UInt16;

    public partial class CPU
    {
        public delegate void OnClockComingHandler(ref uint cycle, ref int cr);
        public delegate void OnCheckRstFlagHandler(ref uint cycle, ref Registers reg);
        public delegate void OnCheckIrqFlagHandler(ref uint cycle, ref Registers reg);
        public delegate void OnCheckNmiFlagHandler(ref uint cycle, ref Registers reg);
        public delegate void OnInstructionFetchHandler(ref uint cycle, ref Registers reg);
        public delegate void OnAddressingHandler(ref uint cycle, ref Registers reg, ref byte cmd);
        public delegate void AfterAddressingHandler(ref uint cycle, ref Registers reg, ref addr ad);
        public delegate void AfterExecuteHandler(ref uint cycle, ref Registers reg, ref int cr);

        /// <summary>
        /// 程序指针变化事件的委托
        /// </summary>
        public delegate void OnPcChangeHandler(addr val);

        /// <summary>
        /// 寄存器状态变化事件的委托
        /// </summary>
        public delegate void OnRegisterChangeHandler(REGISTER_BYTE reg, byte val);

        /// <summary>
        /// CPU时钟周期到来时触发事件
        /// </summary>
        public event OnClockComingHandler OnClockComing;

        /// <summary>
        /// 查验RstFlag以决定是否启动Rst中断时触发事件
        /// </summary>
        public event OnCheckRstFlagHandler OnCheckRstFlag;

        /// <summary>
        /// 查验IrqFlag以决定是否启动Irq中断时触发事件
        /// </summary>
        public event OnCheckIrqFlagHandler OnCheckIrqFlag;

        /// <summary>
        /// 查验NmiFlag以决定是否启动Nmi中断时触发事件
        /// </summary>
        public event OnCheckNmiFlagHandler OnCheckNmiFlag;

        /// <summary>
        /// CPU取指前触发事件
        /// </summary>
        public event OnInstructionFetchHandler OnInstructionFetch;

        /// <summary>
        /// CPU取指后，按指令及操作数寻址前触发事件
        /// </summary>
        public event OnAddressingHandler OnAddressing;

        /// <summary>
        /// CPU寻址完成后，执行指令前触发事件
        /// </summary>
        public event AfterAddressingHandler AfterAddressing;

        /// <summary>
        /// CPU执行指令完成后触发事件
        /// </summary>
        public event AfterExecuteHandler OnAfterExecute;

        /// <summary>
        /// 程序指针变化时触发的事件
        /// </summary>
        public event OnPcChangeHandler OnPcChange;

        /// <summary>
        /// 寄存器状态变化时触发的事件
        /// </summary>
        public event OnRegisterChangeHandler OnRegisterChange;
    }
}